package com.ts.api.common.constant.api;


import com.ts.api.common.entity.MsgFormat;

/**
 * 业务异常枚举
 *
 * @author Pan
 */
public enum ApiEnum {

    /** API系统级 */
    API_SIGN_SUC(0, "返回成功"),
    API_EXP_ERROR(500, "系统异常"),
    API_KEY_CACHE_NULL(900, "获取缓存失败"),
    API_CLIENT_ID_ERROR(1000, "商户未配置"),
    API_CLIENT_DISABLE(1001, "该客户端已关闭,请联系平台方重新开启"),
    API_HEADER_ERROR(1002, "请求头非法参数"),
    API_HEADER_TIME_ERROR(1003, "非法时间参数"),
    API_HEADER_EXPIRE(1004, "请求过期"),
    API_SERVICE_CODE_ERROR(1005, "业务编码不存在"),
    API_BODY_ERROR(1006, "消息体为空"),
    API_BODY_DATA_ERROR(1007, "消息内容为空"),
    API_DECRYPT_BODY_EMPTY(1008, "解密消息内容为空"),
    API_DECRYPT_ERROR(1009, "解密失败"),
    API_SIGN_ERROR(1010, "签名失败"),
    API_SIGN_SORT_DATA_ERROR(1011, "签名错误"),
    API_PARAM_ERROR(1012, "不合法参数"),
    API_PARAM_CITY_ERROR(1012, "城市不合法"),
    API_PARAM_PARSE_ERROR(1013, "参数解析失败"),
    API_BIZ_CODE_ERROR(1014, "错误业务编码"),
    API_ACCESS_UNAUTHORIZED(1014, "该商户访问地址错误"),
    API_NULL_FAIL(1014, "错误-[{}]:[{}]"),
    API_VERSION_MODE_ERROR(1014, "请联系管理员,接入错误:渠道版本与接口地址不符合"),

    /** API接收 */
    API_RECEIVE_BODY_MISS(1015, "接收-缺失请求必要参数[{}]"),
    API_RECEIVE_EVENT_MISS(1016, "接收-请求接口方法缺失,请联系平台方补充"),
    API_RECEIVE_REQUIRE_EVENT_ERROR(1017, "接收-请求时[验证参数]失败"),
    API_RECEIVE_DECRYPT_ERROR(1018, "接收-请求时[解密]失败"),
    API_RECEIVE_AREA_ERROR(1019, "接收-暂不支持地区[{}]"),
    API_RECEIVE_VERIFY_SIGN_ERROR(1020, "接收-请求时[签名验证]失败"),
    API_RECEIVE_CONVERT_ERROR(1021, "接收-字段转换失败字段,字段[{}]值[{}]"),
    API_RECEIVE_PLAN_MISS(1022, "解析通知计划时，计划为空"),

    API_RECEIVE_PARSE_DATA_EXCHANGE_ERROR(1030, "接收-请求时[解析接口1]失败"),
    API_RECEIVE_PARSE_DATA_EXCHANGE_NULL(1031, "接收-请求时[解析接口1]失败,空解析对象"),
    API_RECEIVE_RESP_DATA_EXCHANGE_ERROR(1032, "接收-请求时[响应接口1]失败"),

    API_RECEIVE_PARSE_APPLY_ERROR(1040, "接收-请求时[解析接口2]失败"),
    API_RECEIVE_PARSE_APPLY_NULL(1041, "接收-请求时[解析接口2]失败,空解析对象"),
    API_RECEIVE_RESP_APPLY_ERROR(1042, "接收-请求时[响应接口2]失败"),

    /** 进件检测 */
    API_RECEIVE_APPLY_CITY_ERROR(1043, "接收-申请失败,当前发送城市与前置业务城市不符"),
    API_RECEIVE_APPLY_NOW_PLAN_FIELD_ERROR(1044, "接收-进件资质不符"),
    API_RECEIVE_APPLY_EMPTY_PHONE(1045, "接受-非法手机状态[空号/错误号]"),
    /** 进件失败 */
    API_RECEIVE_ORG_ERROR(1050, "接收-发送机构时错误"),
    API_RECEIVE_ORG_FAIL(1051, "接收-机构拒绝"),
    API_RECEIVE_ORG_AMOUNT_MAX(1052, "接收-机构拒绝2"),
    API_RECEIVE_ORG_PLAN_TIME_ERROR(1053, "接收-计划拒绝"),
    API_RECEIVE_ORG_PLAN_MAX_ERROR(1054, "接收-计划拒绝2"),

    /** 投流 */
    API_INFO_FLOW_CONVERT_ERROR(1070, "信息-转化错误"),
    API_INFO_FLOW_MATCH_EMPTY(1071, "未匹配计划"),
    API_INFO_FLOW_MATCH_EXIST(1072, "无法匹配更多计划"),
    API_INFO_FLOW_CITY_CONVERT_ERROR(1073, "城市转换错误-暂不支持[{}]"),

    /** 撞库 */
    // 无地区匹配
    API_DATA_EXCHANGE_MATCH_AREA_EMPTY(1100, "业务失败,暂无无匹配项"),
    // 未开放计划时间
    API_DATA_EXCHANGE_MATCH_PLAN_TIME_EMPTY(1101, "业务失败2,暂无无匹配项"),
    // 资质校验失败
    API_DATA_EXCHANGE_MATCH_FAIL2(1102, "业务失败33,匹配失败"),
    // 存在资质条件，但是返回撞库失败
    API_DATA_EXCHANGE_MATCH_FAIL3(1102, "业务失败34,匹配失败"),
    // 无下游计划撞库成功
    API_DATA_EXCHANGE_MATCH_FAIL(1102, "业务失败3,匹配失败"),
    // 资质与当前所有计划匹配不上
    API_DATA_EXCHANGE_MATCH_EMPTY(1103, "业务失败4,暂无无匹配项"),
    // 地区错误
    API_DATA_EXCHANGE_AREA_ERROR(1104, "业务失败,地区错误"),
    API_DATA_EXCHANGE_DISCARD(1105, "业务失败,重复撞库"),
    //  过滤分发
    API_DATA_EXCHANGE_FILTER_USER(1106, "业务失败5,暂无无匹配项"),

    /** 进件 */
    API_APPLY_FLOW_ERROR(1201, "业务失败,无前置业务流程"),
    API_APPLY_FLOW_ILLEGAL(1202, "业务失败,非法业务流程"),
    API_APPLY_ID_ERROR(1203, "业务失败,applyId查询不到订单号"),
    API_NOTICE_APPLY_TIMEOUT(1210, "太久未进件,进件超时"),

    /** API机构/平台 */
    API_ORG_EVENT_MISS(1300, "发送机构失败,请联系平台方补充"),
    API_PLAT_EVENT_MISS(1301, "发送平台失败,请联系平台方补充"),

    /** 前置业务参数校验 */
    API_USER_INFO_EXIST(2000, "[{}]失败,已存在"),
    API_REQUIRED_CONFIG(2001, "该API未配置必填表单,请联系平台方"),
    API_REQUIRED_PARAM_NULL(2002, "[{}],必填参数缺失"),
    API_REQUIRED_PARAM_EMPTY(2003, "[{}],非法空参数"),
    API_REQUIRED_PARAM_ERROR(2004, "[{}],非法参数值,请填写合法参数"),
    API_REQUIRED_PARAM_VALUE_RANGE_ERROR(2005, "[{}]非法参数值,请填写对应编码"),
    API_REQUIRED_PARAM_VALUE_NOT_EXIST(2006, "[{}]非法参数,此参数不存在"),
    API_REQUIRED_BASE_PARAM_NULL(2007, "[{}]基础参数缺失,请检查参数"),
    API_REQUIRED_BIZ_PARAM_NULL(2008, "[{}]业务参数缺失,请检查参数"),
    API_BIZ_FLOW_EXIST(2009, "失败1,业务已存在"),
    API_BIZ_FLOW_DATA_CHANGE_FAIL(2010, "失败2,业务已失败"),
    API_BIZ_FLOW_APPLY_FAIL(2010, "失败3,流程已失败"),

    /** 通知 */
    API_NOTIFY_DISABLE(5000, "通知失败,渠道关闭中"),
    ;

    private final Integer code;

    private final String msg;

    private ApiEnum(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public Integer getCode() {
        return code;
    }

    public String getMsg() {
        return msg;
    }

    public MsgFormat format(Object... objects) {
        return MsgFormat.createFormat(this.getCode(), this.getMsg(), objects);
    }

}

